<template>
  <div>
    <el-row>
      <el-col>
        <div class="search_wrap">
          <el-form
            :inline="true"
            :model="filters"
            class="demo-form-inline"
            ref="searchForm"
          >
            <el-form-item prop="allTime">
              <el-date-picker
                v-model="filters.allTime"
                :clearable="true"
                type="datetimerange"
                range-separator="至"
                start-placeholder="查询开始日期"
                end-placeholder="查询结束日期"
                :default-time="['00:00:00', '23:59:59']"
              >
              </el-date-picker>
            </el-form-item>
            <el-form-item>
              <el-button icon="el-icon-search" type="primary" @click="onSearch"
                >查询</el-button
              >
              <el-button icon="el-icon-refresh-left" @click="resetForm"
                >重置</el-button
              >
            </el-form-item>
          </el-form>
        </div>
      </el-col>
    </el-row>
    <el-table
      :data="tableList"
      :fit="true"
      highlight-current-row
      v-loading="loading"
      element-loading-text="数据加载中，请稍后..."
      empty-text="对不起，没有找到相关数据"

    >
      <el-table-column type="index" label="序号" align="center" width="140px">
      </el-table-column>
      <el-table-column
          prop="createDate"
          label="心跳记录时间"
          width="auto"
          align="center"
      >
      </el-table-column>
      <el-table-column
        prop="equipName"
        label="呼叫器名称"
        width="auto"
        align="center"
      >
      </el-table-column>
      <el-table-column
          label="电量"
          width="auto"
          align="center"
      >
        <template slot-scope="scope">
          {{ scope.row.power === 1 ? '满电' : scope.row.power === 2 ? '半电' : '电量不足' }}
        </template>
      </el-table-column>
      <el-table-column
          prop="versions"
          label="版本号"
          width="auto"
          align="center"
      >
      </el-table-column>
<!--      <el-table-column
          label="经纬度"
          width="auto"
          align="center"
      >
        <template slot-scope="scope">
            <span>{{ scope.row.longitude }}-{{ scope.row.latitude }}</span>
        </template>
      </el-table-column>
      <el-table-column
          prop="address"
          label="详细地址"
          width="auto"
          align="center"
      >
      </el-table-column>-->
    </el-table>
    <el-pagination
      background
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="page.pageNo"
      :page-sizes="[20, 50, 100]"
      :page-size="page.pageSize"
      layout="total, sizes, jumper, next, pager, prev"
      :total="page.pageTotal"
    ></el-pagination>
  </div>
</template>
<script>
import BeeperApi from "@/api/equip/beeper";
export default {
  props: {
    equipId: Number | String,
    typeName:String
  },
  data() {
    return {
        new_equipId: "",
      dialog: {
        open: false, // 默认隐藏
        title: ""
      },
      tableList: [],
      loading: false,
      page: {
        pageNo: 1,
        pageTotal: 0,
        pageSize: 20
      },
      filters: {
        allTime: []
      }
    };
  },
  created() {
    this.new_equipId = this.equipId;
    this.init();
  },
  watch: {
    equipId(newVal, oldVal) {
      this.new_equipId = newVal;
     if(this.typeName==='heartBeat'){
        this.getData();
      }
    },
    typeName(newVal){
      if(newVal==='heartBeat'){
        this.getData();
      }
    }

  },
  methods: {
    init() {
      this.$Utils.clearData(this.tableList);
    },
    //   handleCreate(val){
    //       // 父组件 调用子组件
    //       this.dialog.open = true; // 显示弹出框
    //       this.dialog.title = "心 跳 记 录";
    //       this.equipId = val
    //       this.getData()
    //   },
    getData() {
      var cond = {
        equipId: this.new_equipId,
        pageNo: this.page.pageNo,
        pageSize: this.page.pageSize,
      };
      if (this.filters.allTime && this.filters.allTime.length > 0) {
        cond.beginDate = this.$Utils.formatDate(
          this.filters.allTime[0],
          "yyyy-MM-dd hh:mm:ss"
        );
        cond.endDate = this.$Utils.formatDate(
          this.filters.allTime[1],
          "yyyy-MM-dd hh:mm:ss"
        );
        this.$Utils.formatDate(this.filters.allTime[0], "yyyy-MM-dd hh:mm:ss");
      }
      this.loading = true;
      BeeperApi.heartbeatPage(cond).then(res => {
        this.page.pageTotal = res.data.total;
        this.tableList = res.data.list;
        this.loading = false;
      });
    },
    handleSizeChange(size) {
      let _this = this;
      _this.page.pageSize = size;
      _this.getData();
    },
    handleCurrentChange(val) {
      let _this = this;
      _this.page.pageNo = val;
      _this.getData();
    },
    resetForm() {
      this.$refs.searchForm.resetFields();
      this.onSearch()
    },
    onSearch() {
      this.loading = true;
      this.page.pageNo = 1;
      this.getData();
    }
  }
};
</script>

<style scoped lang="scss">
.rotate-cartoon {
  animation: cartoon 0.5s linear 0s infinite backwards;
  // -webkit-animation:cartoon .3s linear 0  infinite
}
@keyframes cartoon {
  0% {
    transform: rotate(0);
  }
  100% {
    transform: rotate(360deg);
  }
}
</style>
